package com.youlai.boot.modules.game.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.modules.game.model.vo.GameAchievementVO;
import com.youlai.boot.modules.game.service.GameAchievementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 游戏成就控制器
 *
 * @author 有来技术团队
 */
@Tag(name = "07.游戏成就管理")
@RestController
@RequestMapping("/api/v1/game/achievements")
@RequiredArgsConstructor
public class GameAchievementController {

    private final GameAchievementService gameAchievementService;

    @Operation(summary = "获取用户解锁的成就列表")
    @GetMapping("/user")
    public Result<List<GameAchievementVO>> getUserAchievements(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        List<GameAchievementVO> achievements = gameAchievementService.getUserAchievements(userId);
        return Result.success(achievements);
    }

    @Operation(summary = "获取游戏的成就列表")
    @GetMapping("/game/{gameId}")
    public Result<List<GameAchievementVO>> getGameAchievements(
            @Parameter(description = "游戏ID") @PathVariable Long gameId,
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        List<GameAchievementVO> achievements = gameAchievementService.getGameAchievements(userId, gameId);
        return Result.success(achievements);
    }

    @Operation(summary = "解锁用户成就")
    @PostMapping("/unlock/{achievementId}")
    public Result<Boolean> unlockAchievement(
            @Parameter(description = "成就ID") @PathVariable Long achievementId,
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId) {
        boolean result = gameAchievementService.unlockAchievement(userId, achievementId);
        return Result.success(result);
    }

    @Operation(summary = "检查并解锁游戏时长相关成就")
    @PostMapping("/check/play-time")
    public Result<List<GameAchievementVO>> checkAndUnlockPlayTimeAchievements(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId,
            @Parameter(description = "游戏时长(秒)") @RequestParam Integer playTime) {
        List<GameAchievementVO> newAchievements = gameAchievementService.checkAndUnlockPlayTimeAchievements(userId, playTime);
        return Result.success(newAchievements);
    }

    @Operation(summary = "检查并解锁游戏进度相关成就")
    @PostMapping("/check/progress")
    public Result<List<GameAchievementVO>> checkAndUnlockProgressAchievements(
            @Parameter(description = "用户ID") @RequestParam(required = false) Long userId,
            @Parameter(description = "游戏进度(0-100)") @RequestParam Integer progress) {
        List<GameAchievementVO> newAchievements = gameAchievementService.checkAndUnlockProgressAchievements(userId, progress);
        return Result.success(newAchievements);
    }
} 